const user = {
    state: {
        historyPathList: [],
        token: '',
        chooseTab: 0,  // 首页tab选中
        chooseTabName: '综合',  // 首页tab选中中文
        nineListIndex: 0,   // 主城九区选中的下标
    },

    mutations: {
        SET_HISTORYPATHLIAT: (state, historyPathList) => {
            state.historyPathList = historyPathList;
            let _historyPathList = [];
            if (historyPathList) {
                historyPathList.forEach(item => {
                    let param = {
                        fullPath: item.fullPath,
                        name: item.name,
                        query: item.query,
                    }
                    _historyPathList.push(param)
                })
            }
            sessionStorage.setItem('historyPathList', JSON.stringify(_historyPathList))
        },
        SET_TOKEN: (state, token) => {
            state.token = token;
            sessionStorage.setItem('token', token)
        },
        SET_CHOOSETAB: (state, chooseTab) => {
            state.chooseTab = chooseTab;
            sessionStorage.setItem('chooseTab', chooseTab)
        },
        SET_CHOOSETABNAME: (state, chooseTabName) => {
            state.chooseTabName = chooseTabName;
            sessionStorage.setItem('chooseTabName', chooseTabName)
        },
        SET_NINELISTINDEX: (state, nineListIndex) => {
            state.nineListIndex = nineListIndex;
            sessionStorage.setItem('nineListIndex', nineListIndex)
        },
    },

    actions: {

        // 动态历史路径
        changeHistoryPathList: ({commit}, historyPathList) => {
            commit('SET_HISTORYPATHLIAT', historyPathList)
        },

        // 更改token
        changeToken: ({commit}, token) => {
            commit('SET_TOKEN', token)
        },

        // 更改选中tab
        changeChooseTab: ({commit}, chooseTab) => {
            commit('SET_CHOOSETAB', chooseTab)
        },

        // 更改选中tab
        changeChooseTabName: ({commit}, chooseTabName) => {
            commit('SET_CHOOSETABNAME', chooseTabName)
        },

        // 更改选中的主城区域
        changeNineListIndex: ({commit}, nineListIndex) => {
            commit('SET_NINELISTINDEX', nineListIndex)
        },

    },

}

export default user

/*
* 使用例子
* */
// store.dispach('changAvatar',param)
